﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yule8xCommon.Typelib;
using Yule8xCommon.Applib;
using Yule8xCommon.Db;
using Yule8xModel;
using Yule8xWechat.Applib;

namespace Yule8xWechat.Agent
{
    public partial class ChildUser : System.Web.UI.Page
    {
        protected System.Data.DataTable dtList;
        protected WxUserInfoResult wxUser;
        protected int child_user_count, user_id;
        protected void Page_Load(object sender, EventArgs e)
        {
            user_id = RequestUtil.GetInteger("user_id");
            if (RuntimeDataUtil.CheckDebugModel() && user_id > 0)
            {
                wxUser = UserModels.GetWxUserInfo(user_id);
                if (null == wxUser)
                {
                    ResponseUtil.WriteEnd("user_id无效!");
                }
            }
            else
            {
                wxUser = LoginPageBase.GetLoginInfo();
                if (null == wxUser)
                {
                    Response.Redirect(WechatUrls.GetUserInfoUrl("agent"), true);
                }
            }
            /*
            object loginData = Session["login"];
            if (null != loginData)
            {
                wxUser = loginData as WxUserInfoResult;
            }
            if (null == loginData || null == wxUser)
            {
                Response.Redirect(WechatUrls.GetUserInfoUrl("agent"), true);
            }
            */
            string sqlstmt = string.Format("select u.nickname, u.is_agent, u.regist_time, f.recharge_amount_total from t_user u left join t_user_finance_statistics f on u.user_id=f.user_id where u.parent1_uid={0} or u.parent2_uid={0} order by u.user_id desc", wxUser.user_id);
            LogUtil.Instance.WriteInfo("[推广玩家详情] " + sqlstmt);
            dtList = DbFactory.Init(AppInfo.conn_yule8x_agent).ExecuteDataTable(sqlstmt);

            sqlstmt = string.Format("select count(0) from t_user where parent1_uid={0} or parent2_uid={0}", wxUser.user_id);
            child_user_count = DbFactory.Instance.ExecuteCount(sqlstmt);
        }

        protected string ShortText(object value,int length,string defv="-")
        {
            return StringUtil.Substring(value, length, defv);
        }
    }
}